﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Rose.Helper;
using Rose.Models;
using System.Web.Security;

namespace Rose.Helper
{
    public class AccountHelpModel
    {
        private   Database_RoseEntities db = new Database_RoseEntities();

        

        public   bool FullRegisterUserInfo(RegisterModel model)
        {
            UserInfo userInfo = new UserInfo()

            {

               Id=model.UserName,

                IsMan = true,

                ////这里我没有返回错误，而是采用了截取长度来注册用户
                Name = string.Empty,
                
                University = model.University??string.Empty,
                College=string.Empty,
                Major =string.Empty,
                SchoolYear =DateTime.Now.Year-1,

                Hit = 0,
                FocusCount = 0,
                FriendCount = 0,
                Score = 5,
                HasLover = false,
                BeFocusCount = 0,
                Email=model.UserName,
               AddressCity=string.Empty,
               AddressProvince=string.Empty,
               AddressStreet=string.Empty,
               AddressTown=string.Empty,
               

               
                ClassRoom = string.Empty,
                ImagePath = Rose.ViewRes.Defaultresx.DefaultHeadImage,
                LoverId = string.Empty,
                Phone = string.Empty,
                QQ = string.Empty,
                SchoolId = string.Empty,
                WebSite = string.Empty,
                PhotoCount=0,
                Hobby=string.Empty
                
            };
           

            try
            {
                db.AddToUserInfos(userInfo);
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }


       

       
        public   string GetRegisterError(MembershipCreateStatus createStatus)
        {
            switch (createStatus)
            {
                case MembershipCreateStatus.DuplicateUserName:
                    return "邮箱已注册。请另输入一个邮箱账号。";

                case MembershipCreateStatus.DuplicateEmail:
                    return "邮箱已注册。请另输入一个邮箱账号。";

                case MembershipCreateStatus.InvalidPassword:
                    return "提供的密码无效。请输入有效的密码值。";

                case MembershipCreateStatus.InvalidEmail:
                    return "提供的电子邮件地址无效。请检查该值并重试。";

                case MembershipCreateStatus.InvalidAnswer:
                    return "提供的密码取回答案无效。请检查该值并重试。";

                case MembershipCreateStatus.InvalidQuestion:
                    return "提供的密码取回问题无效。请检查该值并重试。";

                case MembershipCreateStatus.InvalidUserName:
                    return "提供的用户名无效。请检查该值并重试。";

                case MembershipCreateStatus.ProviderError:
                    return "身份验证提供程序返回了错误。请验证您的输入并重试。如果问题仍然存在，请与系统管理员联系。";

                case MembershipCreateStatus.UserRejected:
                    return "已取消用户创建请求。请验证您的输入并重试。如果问题仍然存在，请与系统管理员联系。";

                default:
                    return "发生未知错误。请验证您的输入并重试。如果问题仍然存在，请与系统管理员联系。";
            }
        }
    }
}